package com.lovo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.system.dto.PageDto;
import com.lovo.system.dto.PurchaseMesDto;
import com.lovo.system.service.IPurchaseMesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/purchaseMes")
public class PurchaseMesController {

    @Autowired
    IPurchaseMesService purchaseMesService;

    @RequestMapping("/info")
    public IPage<PurchaseMesDto> info(@RequestBody PageDto<PurchaseMesDto> pageDto){
        return purchaseMesService.info(pageDto.getCurPage(),pageDto.getPageSize(),pageDto.getStartTime(),
                pageDto.getEndTime(),pageDto.getData().getPurchaseMesName());
    }

    @RequestMapping("/add")
    public int addPurchaseMes(@RequestBody PurchaseMesDto purchaseMesDto) {
        try {
            purchaseMesDto.setPurchaseMesDate(LocalDate.now());
            return purchaseMesService.insertPurchaseMes(purchaseMesDto);
        }catch (Exception e){
            return 0;
        }
    }
}
